package logic

import (
	"context"
	"shuqi-novel/models/mysql"

	"shuqi-novel/novelrpc/internal/svc"
	"shuqi-novel/novelrpc/novelrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserAddLogic {
	return &UserAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UserAddLogic) UserAdd(in *novelrpc.UserAddRequest) (*novelrpc.UserAddResponse, error) {
	// todo: add your logic here and delete this line
	var user mysql.User
	user = mysql.User{
		Title: in.Title,
		Price: float64(in.Price),
		Text:  in.Text,
	}
	mysql.DB.Debug().Create(&user)
	return &novelrpc.UserAddResponse{
		UserId: int64(user.ID),
	}, nil
}
